package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCDemo7 {
    public static void main(String[] args) {
        try(Connection connection=DBUtil.getConnection();){
            Statement statement = connection.createStatement();
            String sql="SELECT s.name,s.gender,s.age,s.job,c.name,c.floor\n" +
                    "FROM student s\n" +
                    "JOIN class c ON s.class_id=c.id\n" +
                    "WHERE c.name='1年级1班'";
            ResultSet rs=statement.executeQuery(sql);
            while(rs.next()){
                String sName=rs.getString("s.name");
                String gender=rs.getString("s.gender");
                int age=rs.getInt("s.age");
                String job=rs.getString("s.job");
                String cName=rs.getString("c.name");
                int floor=rs.getInt("c.floor");
                System.out.println(sName+"-"+gender+"-"+age+"-"+job+"-"+cName+"-"+floor);
            }
        }catch(SQLException e){
            e.printStackTrace();
        }
    }
}
